import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILayer } from "../../../mvc/interfaces/ILayer";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { Cache } from "../../cache/Cache";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { GangFightsSelectFaceWindow } from "./GangFightsSelectFaceWindow";
import { MsgManager } from "../../manager/MsgManager";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GangfightsCreateTeamData } from "./data/GangfightsCreateTeamData";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { GTextInput } from "../../../../com/mui/controls/GTextInput";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class GangFightsCreateTeamWindow
    
    export  class GangFightsCreateTeamWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            setSize(330, 278);
            titleHeight = 26;
            title = Language.getString(44455);
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            ObjCreate.createBg(18, 38, 292, 192, this);
            ObjCreate.createTextField(Language.getString(44456), 32, 50, 65, 20, this);
            this._tiTeamName = ObjCreate.createGTextInput(94, 50, 148, 26, this);
            this._tiTeamName.setStyle("textPadding", 3);
            this._tiTeamName.maxChars = 7;
            ObjCreate.createTextField(Language.getString(44457), 32, 83, 65, 20, this);
            ObjCreate.createBg(94, 84, 64, 64, this);
            this._bmpTeamSign = new Object /* flash.display.Bitmap */();
            ObjCreate.setObjAttri(this._bmpTeamSign, 97, 86, -1, -1, this);
            this._btnChangeSign = ObjCreate.createGButton(Language.getString(44458), 89, 147, 70, 28, this, "LinkButton");
            this._btnChangeSign.addEventListener(flash.events.MouseEvent.CLICK, this.onClickChangeSign);
            this._tfScoreDes = ObjCreate.createTextField(Language.getString(44459), 32, 177, 65, 20, this);
            this._tfScore = ObjCreate.createTextField("", 92, 177, 180, 20, this);
            var loc1=int(Cache.instance.role.combatCapabilities);
            this._tfScore.htmlText = "<font color = \'#FF7902\'>" + 12000 + "</font>";
            ObjCreate.createTextField(Language.getString(44460), 32, 202, 65, 20, this);
            ObjCreate.createTextField("100000", 92, 202, 65, 20, this, GlobalStyle.textFormatOrange);
            this._btnCreateTeam = ObjCreate.createGButton(Language.getString(44455), 135, 236, 70, 26, this);
            this._btnCreateTeam.addEventListener(flash.events.MouseEvent.CLICK, this.onClickCreateTeam);
            LoaderHelp.addResCallBack(ResFileConst.GangFightsFace, this.onResCompl);
            this.faceId = Math.floor(Math.random() * 12) + 1;
            return;
        }

        /* internal  */onClickChangeSign(arg1: Object /* flash.events.MouseEvent */): void
        {
            GangFightsSelectFaceWindow.instance.show();
            GangFightsSelectFaceWindow.instance.x = 337;
            GangFightsSelectFaceWindow.instance.y = 0;
            return;
        }

        /* internal  */onClickCreateTeam(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._tiTeamName.text.length == 0) 
            {
                MsgManager.showRollTipsMsg(Language.getString(44464));
                return;
            }
            if (!this._faceId) 
            {
                MsgManager.showRollTipsMsg(Language.getString(44461));
                return;
            }
            if (this._isModifyMode) 
            {
                if (Cache.instance.gangFights.myTeamInfo && this._tiTeamName.text == Cache.instance.gangFights.myTeamInfo.name && this._faceId == Cache.instance.gangFights.myTeamInfo.faceId) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(44462));
                    return;
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.GangFightsModifyTeam, new GangfightsCreateTeamData(this._tiTeamName.text, this._faceId)));
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GangFightsCreateTeam, new GangfightsCreateTeamData(this._tiTeamName.text, this._faceId)));
            }
            return;
        }

        /* internal  */onResCompl(): void
        {
            this._isResCompl = true;
            this.updateFace();
            return;
        }

        public set faceId(arg1: int)
        {
            this._faceId = arg1;
            this.updateFace();
            return;
        }

        public updateFace(): void
        {
            if (this._faceId > 0 && this._isResCompl) 
            {
                this._bmpTeamSign.bitmapData = GlobalClass.getBitmapData(GameDefConfig.instance.getGangFightsFaceName(this._faceId));
            }
            return;
        }

        public set isModifyMode(arg1: Boolean)
        {
            this._isModifyMode = arg1;
            this._tfScore.visible = !this._isModifyMode;
            this._tfScoreDes.visible = !this._isModifyMode;
            if (this._isModifyMode) 
            {
                title = Language.getString(44463);
                this._btnCreateTeam.label = Language.getString(44463);
            }
            else 
            {
                title = Language.getString(44455);
                this._btnCreateTeam.label = Language.getString(44455);
            }
            return;
        }

        public updateTeamMsg(arg1: string, arg2: int): void
        {
            this.faceId = arg2;
            this._tiTeamName.text = arg1;
            return;
        }

        public static get instance(): GangFightsCreateTeamWindow
        {
            if (!GangFightsCreateTeamWindow._instance) 
            {
                GangFightsCreateTeamWindow._instance = new GangFightsCreateTeamWindow();
            }
            return GangFightsCreateTeamWindow._instance;
        }

        public static hasInstance(): Boolean
        {
            return !(GangFightsCreateTeamWindow._instance == null);
        }

        /* internal */ /* var */_tiTeamName: GTextInput;

        /* internal */ /* var */_bmpTeamSign: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_btnChangeSign: GButton;

        /* internal */ /* var */_tfScoreDes: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfScore: Object /* flash.text.TextField */;

        /* internal */ /* var */_btnCreateTeam: GButton;

        /* internal */ /* var */_faceId: int=0;

        /* internal */ /* var */_isModifyMode: Boolean=false;

        /* internal */ /* var */_isResCompl: Boolean=false;

        /* internal */ static /* var */_instance: GangFightsCreateTeamWindow;
    }
